home *** CD-ROM | disk | FTP | other *** search
/ PC Graphics Unleashed / PC Graphics Unleashed.iso / ch01 / newss24x.asm < prev    next >
Assembly Source File  |  1993-11-09  |  15KB  |  404 lines

  1. ;--------------------------------------------------------------------------
  2. ; This is file NEW24X.ASM
  3. ;
  4. ; Copyright (C) 1993 Denis Bos, Einsteinstr 37, 6533 NG
  5. ;                               Nijmegen, The Netherlands
  6. ;
  7. ; Just kidding about the copyright, but the adres is correct
  8. ;
  9. ; A friend of mine (actually a roomy) had the 'normal' version of
  10. ; this driver, but it didn't work for 24-bit, so I looked at a few
  11. ; drivers and the book (that came with the Speedstar 24x), and came
  12. ; up with this driver, which looks remarkebly the same as the 'nor-
  13. ; mal' version (ss24x.asm), but with an additional mode for 24-bit
  14. ;
  15. ; I hope it works with all the other modes as well, haven't had time
  16. ; to test them all (just most of the graphics-modes).
  17. ;
  18. ; This file is distributed WITHOUT ANY WARRANTY; without even the implied
  19. ; warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. (??!)
  20. ;
  21. ; I added the 24-bit mode (mode 72h) support on 24-10-93
  22. ; Compiled with MASM it should work (it did on my computer)
  23. ;
  24. ; PS2: I removed the req_... stuff, because i didn't have any (include)
  25. ;    file in which was described what val_... was, but I don'd think those
  26. ;    modes are that important. 24-bit is!! (You probably can just add them
  27. ;    again..)  :-)
  28. ;--------------------------------------------------------------------------
  29.  
  30.     .386
  31. include grdriver.inc
  32. cseg    segment byte public use16 'code'
  33.     assume  cs:cseg, ds:cseg, es:cseg, ss:nothing
  34.  
  35. ;--------------------------------------------------------------------------
  36. ; DRIVER HEADER
  37. ;  The following entries MUST match the structure and constant
  38. ;  declarations in the file 'grdriver.h' of the GRX graphics library
  39. ;  The mode word should contain the following bitfields:
  40. ;     - the GRD_NEW_DRIVER bit set for any new format driver
  41. ;     - the adapter type field should be specified
  42. ;     - the memory size field should be specified
  43. ;     - the paging mode field should be specified
  44. ;  The mode set routine will OR in the plane bitfield as it will
  45. ;  change when different color number modes are requested.
  46. ;--------------------------------------------------------------------------
  47.  
  48.     dw      offset mode_set_routine
  49.     dw      offset paging_routine
  50. mode_W  dw      GRD_NEW_DRIVER+GRD_VGA+GRD_1024K+GRD_RW_64K
  51. ;
  52. ; The 'def_xx' fields are filled in by go32 from the corresponding
  53. ; fields of the 'GO32' environment variable
  54. ;
  55. def_tw  dw      80              ; text width
  56. def_th  dw      25              ; text height
  57. def_gw  dw      640             ; graphics width
  58. def_gh  dw      480             ; graphics height
  59. def_nc  dw      16              ; graphics colors
  60.     dw      offset driver_init_routine
  61.     dw      offset text_mode_table
  62.     dw      offset graphics_mode_table
  63.  
  64. ;
  65. ; Biggest text and graphics sizes
  66. ;
  67. Max_TW  equ     132
  68. Max_TH  equ     50
  69. Max_GWn equ     1024            ; non interlaced!!!
  70. Max_GHn equ     768
  71. Max_GW  equ     1280            ; may be interlaced
  72. Max_GH  equ     1024
  73.  
  74. ;--------------------------------------------------------------------------
  75. ; TABLE OF SUPPORTED TEXT MODES
  76. ;       - keep sorted by size
  77. ;       - end with an all 0 entry
  78. ;       - BIOS field = 0xff disables it
  79. ;       - fields:
  80. ;               width,  height, colors, BIOS#+  setup_procedure_index*256
  81. ;--------------------------------------------------------------------------
  82. text_mode_table         label word
  83.     dw      80,     25,     2,      007h +  00000h
  84.     dw      40,     25,     16,     001h +  00000h
  85.     dw      80,     25,     16,     003h +  00000h
  86.     dw      80,     34,     16,     041h +  00000h
  87.     dw      80,     43,     16,     067h +  00000h
  88.     dw      80,     50,     16,     066h +  00000h
  89.     dw      132,    25,     16,     055h +  00000h
  90.     dw      132,    28,     16,     047h +  00000h
  91.     dw      132,    43,     16,     054h +  00000h
  92.     dw      132,    44,     16,     021h +  00000h
  93.     dw      132,    50,     16,     069h +  00000h
  94.     dw      0,      0,      0,      000h +  00000h
  95.  
  96. ;--------------------------------------------------------------------------
  97. ; TABLE OF SUPPORTED GRAPHICS MODES
  98. ;       - keep sorted first by colors then by size
  99. ;       - end with an all 0 entry
  100. ;       - BIOS field = 0xff disables it
  101. ;       - fields:
  102. ;               width,  height, colors, BIOS#+  setup_procedure_index*256
  103. ;--------------------------------------------------------------------------
  104. graphics_mode_table     label word
  105.     dw      320,    200,    16,     00dh +  00000h
  106.     dw      640,    200,    16,     00eh +  00000h
  107.     dw      640,    350,    16,     010h +  00000h
  108.     dw      640,    480,    16,     012h +  00000h
  109.     dw      800,    600,    16,     058h +  00000h
  110.     dw      1024,   768,    16,     05dh +  00000h
  111.     dw      1280,   960,    16,     06ch +  00000h
  112.     dw      1280,   1024,   16,     064h +  00000h
  113.     
  114.     dw      320,    200,    256,    013h +  00000h
  115.     dw      640,    400,    256,    05eh +  00000h
  116.     dw      640,    480,    256,    05fh +  00000h
  117.     dw      800,    600,    256,    05ch +  00000h
  118.     dw      1024,   768,    256,    060h +  00000h
  119.     
  120.     dw      640,    480,    32768,  062h +  00000h
  121.     dw      800,    600,    32768,  063h +  00000h
  122.     
  123.     dw      640,    480,    0c018h, 072h +  00000h  ; The extra mode         
  124.     
  125.     dw      0,      0,      0,      000h +  00000h
  126.  
  127.  
  128. ;--------------------------------------------------------------------------
  129. ; TABLE OF SPECIAL SETUP PROCEDURES
  130. ;  You may need such procedures for:
  131. ;     -- reloading fonts on standard EGA or VGA for
  132. ;        higher resolution text modes
  133. ;     -- enable HiColor mode of some Super VGAs
  134. ;     -- Handle the parameter passing conventions of the VESA BIOS
  135. ;     -- put VGA into 256 color plane mode ("MODE X")
  136. ;     -- etc...
  137. ;  There should be one entry in the table for every non-zero
  138. ;  'setup_procedure_index' in the text and graphics mode tables.
  139. ;  The first entry in the table belongs to index 100h, and so on.
  140. ;  The special setup procedure is invoked via a near call.
  141. ;
  142. ;  Entry: DI=address of the mode record from the text or graphics
  143. ;         table to set up.
  144. ;
  145. ;  Exit:  Adapter configured
  146. ;         BX=driver mode word as it should be returned by the mode set
  147. ;            routine. Typically it involves picking up the mode word
  148. ;            from the header and OR-ing in the appropriate bitplane mode
  149. ;            bitfield. (This is not needed for text modes)
  150. ;         AX, CX, DX, SI can be trashed, PRESERVE DI!!!!
  151. ;
  152. ;  NOTE: This runs in real mode, but don't mess with the segment registers.
  153. ;--------------------------------------------------------------------------
  154. special_setup_table     label word
  155.     dw      offset  VGA_50row_mode_set
  156. ;
  157. ; Routine to set up VGA 50 row mode
  158. ; interface is described above
  159. ;
  160. VGA_50row_mode_set      proc    near
  161.     mov     ax,03h                  ; set 80x25 mode
  162.     int     10h
  163.     xor     bx,bx
  164.     mov     ax,1112h                ; load 8x8 font
  165.     int     10h
  166.     ret
  167. VGA_50row_mode_set      endp
  168.  
  169. ;--------------------------------------------------------------------------
  170. ; DRIVER INIT ROUTINE
  171. ;  called once after the driver is loaded
  172. ;  may do one or more of the followings:
  173. ;    - check for proper board type
  174. ;    - check amount of RAM on board, and:
  175. ;       -- update word in header to reflect correct amount
  176. ;       -- disable modes in the tables for which there is not enough RAM
  177. ;    - check for special equipment (HiColor DAC, etc...)
  178. ;
  179. ;  Entry: nothing
  180. ;
  181. ;  Exit:  AX=status:
  182. ;          non-zero: OK,
  183. ;          0: something went wrong (e.g. wrong adapter, etc..)
  184. ;         BX,CX,DX may be trashed
  185. ;
  186. ;  NOTE: This runs in real mode, but don't mess with the segment registers.
  187. ;--------------------------------------------------------------------------
  188. driver_init_routine     proc    far
  189.     mov     dx,03ceh
  190.     mov     ax,0e0bh
  191.     out     dx,ax                   ; enable second bank register
  192.     mov     dx,03c5h
  193.     mov     ax,0ff11h               ; set bank registers for R/W banking
  194.     out     dx,ax                   ;  at B000:0000 - B000:FFFF
  195.     ret
  196. driver_init_routine     endp
  197.  
  198. ;--------------------------------------------------------------------------
  199. ; MODE SET ROUTINE
  200. ;  sets up a text or graphics mode as close as possible to the one
  201. ;  reguested by the user with regard to number of colors and size.
  202. ;
  203. ;  Entry: AX=mode selection
  204. ;     0 = 80x25 text
  205. ;     1 = default text
  206. ;     2 = text CX cols by DX rows
  207. ;     3 = biggest text
  208. ;     4 = 320x200 graphics
  209. ;     5 = default graphics
  210. ;     6 = graphics CX width by DX height
  211. ;     7 = biggest non-interlaced graphics
  212. ;     8 = biggest graphics
  213. ;     9 = graphics BX colors, CX width by DX height
  214. ;
  215. ;  Exit: BX=driver mode flag
  216. ;        CX=width (in pixels or characters)
  217. ;        DX=height
  218. ;
  219. ;  NOTE: This runs in real mode, but don't mess with the segment registers.
  220. ;        YOU SHOULD NOT NEED TO CHANGE THIS ROUTINE AS IT IS PRETTY
  221. ;        MUCH TABLE DRIVEN
  222. ;--------------------------------------------------------------------------
  223. mode_set_routine        proc    far
  224.     push    ds
  225.     push    di
  226.     push    si
  227.     mov     si,cs
  228.     mov     ds,si
  229.     cmp     ax,9
  230.     jbe     DoIt
  231.     jmp     Exit
  232. DoIt:   add     ax,ax
  233.     mov     si,ax
  234.     jmp     WORD PTR mode_set_table[si]
  235. mode_set_table  label   word
  236.     dw      offset mode_0
  237.     dw      offset mode_1
  238.     dw      offset mode_2
  239.     dw      offset mode_3
  240.     dw      offset mode_4
  241.     dw      offset mode_5
  242.     dw      offset mode_6
  243.     dw      offset mode_7
  244.     dw      offset mode_8
  245.     dw      offset mode_9
  246. mode_0: mov     si,offset text_mode_table       ; 80x25 text
  247.     mov     bx,def_nc
  248.     mov     cx,80
  249.     mov     dx,25
  250.     jmp     Lookup
  251. mode_1: mov     si,offset text_mode_table       ; default text
  252.     mov     bx,def_nc
  253.     mov     cx,def_tw
  254.     mov     dx,def_th
  255.     jmp     Lookup
  256. mode_2: mov     si,offset text_mode_table       ; CX*DX text
  257.     mov     bx,def_nc
  258.     jmp     Lookup
  259. mode_3: mov     si,offset text_mode_table       ; biggest text
  260.     mov     bx,def_nc
  261.     mov     cx,Max_TW
  262.     mov     dx,Max_TH
  263.     jmp     Lookup
  264. mode_4: mov     si,offset graphics_mode_table   ; 320x200 graphics
  265.     mov     bx,def_nc
  266.     mov     cx,320
  267.     mov     dx,200
  268.     jmp     Lookup
  269. mode_5: mov     si,offset graphics_mode_table   ; default graphics
  270.     mov     bx,def_nc
  271.     mov     cx,def_gw
  272.     mov     dx,def_gh
  273.     jmp     Lookup
  274. mode_6: mov     si,offset graphics_mode_table   ; CX*DX graphics
  275.     mov     bx,def_nc
  276.     jmp     Lookup
  277. mode_7: mov     si,offset graphics_mode_table   ; biggest non-interlaced gr
  278.     mov     bx,def_nc
  279.     mov     cx,Max_GWn
  280.     mov     dx,Max_GHn
  281.     jmp     Lookup
  282. mode_8: mov     si,offset graphics_mode_table   ; biggest graphics
  283.     mov     bx,def_nc
  284.     mov     cx,Max_GW
  285.     mov     dx,Max_GH
  286.     jmp     Lookup
  287. mode_9: mov     si,offset graphics_mode_table   ; CX*DX graphics w/ BX colors
  288. ;
  289. ; At this point:
  290. ;   SI points to the table to search (text or graphics)
  291. ;   BX has colors
  292. ;   CX has width
  293. ;   DX has height
  294. ;
  295. Lookup: xor     ax,ax                           ; last color number seen
  296. Find_C: cmp     [si+4],ax                       ; last color number == this?
  297.     je      Same_C
  298.     jb      Prev_C                          ; end of table -- use last color
  299.     cmp     BYTE PTR [si+6],0ffh            ; valid entry ?
  300.     je      Prev_C                          ; not -- use last color
  301.     mov     ax,[si+4]                       ; record color number
  302.     mov     di,si                           ; start of entries w/ this color
  303.     cmp     ax,bx                           ; enough colors ?
  304.     jae     Find_S
  305. Same_C: add     si,8
  306.     jmp     Find_C
  307. Prev_C: or      ax,ax                           ; found any color at all?
  308.     je      Exit
  309. ;
  310. ; At this point:
  311. ;   DI points into the table to the first entry with the desired color
  312. ;      number (either it has enough colors or it is the highest color
  313. ;      number supported by the driver). Additionally, at least the
  314. ;      first (= smallest size) entry for this color is valid (has a
  315. ;      valid BIOS number).
  316. ;   AX has the color number adjusted for the driver
  317. ;   CX has width
  318. ;   DX has height
  319. ;
  320. Find_S: cmp     [di+4],ax                       ; still the same color #?
  321.     jne     Prev_S
  322.     cmp     BYTE PTR [di+6],0ffh            ; valid entry ?
  323.     je      Prev_S
  324.     cmp     [di],cx
  325.     jb      Next_S
  326.     cmp     [di+2],dx
  327.     jae     GotIt
  328. Next_S: add     di,8
  329.     jmp     Find_S
  330. Prev_S: sub     di,8
  331. ;
  332. ; At this point:
  333. ;   DI points to the table entry we want to set up
  334. ;
  335. GotIt:  mov     ax,[di+6]                       ; BIOS mode number
  336.     or      ah,ah                           ; special ?
  337.     je      doBIOS
  338.     mov     al,ah
  339.     xor     ah,ah
  340.     dec     ax
  341.     add     ax,ax
  342.     mov     si,ax
  343.     call    WORD PTR special_setup_table[si]
  344.     jmp     RetVal
  345. doBIOS: int     10h
  346.     mov     bx,GRD_1_PLANE
  347.     cmp     WORD PTR [di+4],2               ; 2 colors ?
  348.     je      doFLAG
  349.     mov     bx,GRD_4_PLANES
  350.     cmp     WORD PTR [di+4],16              ; 16 colors ?
  351.     je      doFLAG
  352.     mov     bx,GRD_8_PLANES
  353.     cmp     WORD PTR [di+4],256             ; 256 colors ?
  354.     je      doFLAG
  355.     mov     bx,GRD_16_PLANES
  356.     cmp     WORD PTR [di+4],32768           ; 32K colors ?
  357.     je      doFLAG
  358.     mov     bx,GRD_24_PLANES
  359.     cmp     WORD PTR [di+4],0c018h          ; 16M colors ?
  360.     je      doFLAG
  361.     mov     bx,GRD_PLANE_MASK               ; something is wrong!!
  362. doFLAG: or      bx,mode_W
  363. RetVal: mov     cx,[di]
  364.     mov     dx,[di+2]
  365. Exit:   pop     si
  366.     pop     di
  367.     pop     ds
  368.     ret
  369. mode_set_routine        endp
  370.  
  371. ;--------------------------------------------------------------------------
  372. ; PAGING ROUTINE
  373. ;
  374. ;  Entry: AH=read page
  375. ;         AL=write page
  376. ;
  377. ;  Exit: VGA configured.
  378. ;        AX,BX,CX,DX,SI,DI may be trashed
  379. ;
  380. ;  NOTE: This runs in protected mode!  Don't mess with the segment registers!
  381. ;        This code must be relocatable and may not reference any data!
  382. ;--------------------------------------------------------------------------
  383.     assume  ds:nothing, es:nothing
  384.  
  385. paging_routine  proc    far
  386.     mov     cl,4
  387.     shl     ah,cl ; WD90C3x offset registers have 4k granularity
  388.     shl     al,cl ; => multiply by 16 to get normal VGA 64k bank granularity
  389.     mov     bh,al
  390.     mov     bl,0ah                  ; write bank gets PR0B index code
  391.     mov     al,09h                  ; read bank gets PR0A index code
  392.     mov     dx,03ceh                ; load graphics index register number
  393.     out     dx,ax                   ; set PR0A (read bank)
  394.     mov     ax,bx
  395.     out     dx,ax                   ; set PR0B (write bank)
  396.     ret
  397. paging_routine  endp
  398.  
  399.  
  400. cseg    ends
  401.     end
  402.  
  403.  
  404.